<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="com.lmpop.trade.ti_organize.*" %>
<%@page import="java.util.*" %>
<%@page import="com.lmpop.frame.util.PageTools" %>
<%
	request.setCharacterEncoding("UTF-8");
	Map ti_organize = new Hashtable();
	String s_title = "";
	
	String s_cust_id = "";	
	if( session.getAttribute("session_cust_id") != null ){
		s_cust_id = session.getAttribute("session_cust_id").toString();
		ti_organize.put("cust_id",s_cust_id);
	}

	String up_orgId = "";
	if (request.getParameter("up_org_id") != null && !request.getParameter("up_org_id").equals("")) {
		up_orgId = request.getParameter("up_org_id");
	}else{
		up_orgId = "000000000000000";
	}
	if(request.getParameter("s_title")!=null && !request.getParameter("s_title").equals("")){
		s_title = request.getParameter("s_title");
		ti_organize.put("org_name",s_title);
		//up_orgId = "";
	}
	if(request.getParameter("z_org_class")!=null && !request.getParameter("z_org_class").equals("")){
	String org_class=request.getParameter("z_org_class").toString();
		ti_organize.put("org_class",org_class);
	}
	
	ti_organize.put("up_org_id",up_orgId);
	Ti_organizeInfo ti_organizeInfo = new Ti_organizeInfo();
	String iStart = "0";
	int limit = 20;
	if(request.getParameter("iStart")!=null) iStart = request.getParameter("iStart");
	List list = ti_organizeInfo.getListByPage(ti_organize,Integer.parseInt(iStart),limit);
	int counter = ti_organizeInfo.getCountByObj(ti_organize);
	String pageString = new PageTools().getGoogleToolsBar(counter,"index.jsp?s_title="+s_title+"&up_org_id="+up_orgId+"&iStart=",Integer.parseInt(iStart),limit);
	String uporgId  = ti_organizeInfo.getUp_org_id(up_orgId);
	
	String para = "s_title="+s_title+"&up_org_id="+up_orgId+"&iStart="+Integer.parseInt(iStart);
%>
<html>
  <head>
   	<title>组织结构管理</title>
	<link href="/program/admin/index/css/style.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="/js/commen.js" charset="UTF-8"></script>
	<script type="text/javascript" src="organize.js" charset="UTF-8" ></script>
</head>

<body>
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td width="90%">
				<h1>组织结构管理</h1>
			</td>
			<td>
				<a href="addInfo.jsp"><img src="/program/admin/index/images/post.gif" /></a>
			</td>
		</tr>
	</table>
	
	<form action="index.jsp" name="indexForm" method="post">
	
	
	<table width="100%" cellpadding="0" cellspacing="0" class="dl_su">
		<tr>
			<td align="left">
				部门：<input name="s_title" type="text" onBlur="this.value=trim(this.value)" />
				<input name="searchInfo" type="button" value="查询" onclick="return search()" />	
			</td>
		</tr>
	</table>

	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="tablehe">
		<tr><td align="center"><%=pageString%></td></tr>
	</table>
	
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="dl_bg">
		<tr>
			<td width="90%">
				<input type="button" name="delInfo" onclick="delIndexInfos()" value="删除" class="buttab"/>
		<%if(!up_orgId.equals("000000000000000")){         %>																				<!--fixed by Zhouxq-->
		 		<input type="button" class="buttab" name="fanhui" value="返回" onClick="location.href='index.jsp?up_org_id=<%=uporgId%>'" style="cursor:pointer;">
		<%}%>
			</td>
			<td>
				总计:<%=counter%>条
			</td>
		</tr>
	</table>
		<% 
		int listsize = 0;
		if(list!=null && list.size()>0){
			listsize = list.size();
	%>
	
	<table width="100%" cellpadding="1" cellspacing="1" class="listtab" border="0">
		<tr>
			<th width="5%" align="center"><input type="checkbox" name="checkall" id="checkall" onclick="selectAll()"></th>
			
		  	<th>部门名称</th>
		  	
		  	<th>上级部门</th>
		  	
		  	<th>级别</th>
		  	
		  	<th width="10%">新增下级</th>
		  	
			<th width="10%">修改</th>
	  		<th width="10%">删除</th>
		</tr>
		
		<% 
	  		for(int i=0;i<list.size();i++){
	  			Hashtable map = (Hashtable)list.get(i);
	  			String cust_id="",org_id="",org_name="",up_org_id="",org_class="";
  			  	if(map.get("cust_id")!=null) cust_id = map.get("cust_id").toString();
			  	if(map.get("org_id")!=null) org_id = map.get("org_id").toString();
			  	if(map.get("org_name")!=null) org_name = map.get("org_name").toString();
			  	if(map.get("up_org_id")!=null) up_org_id = map.get("up_org_id").toString();
			  	if(map.get("org_class")!=null) org_class = map.get("org_class").toString();
			  	
			  	Boolean hasDown =  ti_organizeInfo.checkSonById(org_id);	
			  	String up_org_name = ti_organizeInfo.getOrgNameById(up_org_id);
				if(up_org_name.equals("")){
				up_org_name ="无上级分类";
				
				}
		 %>
		
		<tr>
			<td width="5%" align="center"><input type="checkbox" name="checkone<%=i%>" id="checkone<%=i%>" value="<%=org_id%>" /></td>
			
		  	<td>
		  	<%
	  		 if(hasDown){
	  		%>
	  			<input type="hidden" name="hasdown<%=i%>" value="1" id="hasdown<%=i%>" />
	  			<a href="index.jsp?up_org_id=<%=org_id%>" title="查看该部门下级">
				<img src="/program/admin/images/1.gif" border="0" style="cursor:pointer;"/><%=org_name%></a>
	  		<%
	  		}else{
	  		%>
		  		<%=org_name%>
		  	<%}%>
		  	</td>
		  	
		  	<td><%=up_org_name%></td>
		  	
		  	<td><%=org_class%></td>
		  	
		  	<td><a href="addInfo.jsp?up_org_id=<%=org_id%>&org_class=<%=org_class%>"><img src="/program/admin/images/add.gif" border="0" style="cursor:pointer;" /></a></td>
		  	
		  			
  	<input type="hidden" name="z_org_class" id="z_org_class" value="<%=org_class%>" />
		  	
		  	
		  	
			<td width="10%"><a href="updateInfo.jsp?org_id=<%=org_id%>&<%=para%>"><img src="/program/admin/images/edit.gif" title="修改" /></a></td>
	  		<td width="10%">
	  			<a href="javascript:delOneNews('<%=i%>','<%=org_id%>');"><img src="/program/admin/images/delete.gif" title="删除" /></a>
	  		</td>
	  		
 		</tr>
		
		  <%
		  		}
		  %>
		
	</table>
	
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="dl_bg">
	
		<tr>
			<td width="90%">
				<input type="button" name="delInfo" onclick="delIndexInfo()" value="删除" class="buttab"/>				<!--fixed by Zhouxq-->
					<%if(!up_orgId.equals("000000000000000")){%>
					 		<input type="button" class="buttab" name="fanhui" value="返回" onClick="location.href='index.jsp?up_org_id=<%=uporgId%>'" style="cursor:pointer;">
						<%}%>
			</td>
			<td>
				总计:<%=counter %>条
			</td>
		</tr>
	</table>
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="tablehe">
		<tr><td align="center"><%=pageString %></td></tr>
	
	</table>
	
	<%
		 }
	%>
	
	  <input type="hidden" name="listsize" id="listsize" value="<%=listsize%>" />
		<input type="hidden" name="up_org_id" id="up_org_id" value="<%=up_orgId%>" />	  
	  <input type="hidden" name="pkid" id="pkid" value="" />
	  <input type="hidden" name="bpm_id" id="bpm_id" value="4136" />
	  </form>
</body>

</html>
